package com.ley.yikang.service.serviceimpl;

import com.ley.yikang.entity.Child;
import com.ley.yikang.mapper.ChildMapper;
import com.ley.yikang.service.ChildService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ChildServiceImpl implements ChildService {
    private final ChildMapper childMapper;

    @Autowired
    public ChildServiceImpl(ChildMapper childMapper) {
        this.childMapper = childMapper;
    }

    @Override
    public void addChild(Child child) {
        childMapper.addChild(child);
    }

    @Override
    public List<Child> findAll(String childName, String phone, Integer communityId) {
        // 使用Map封装可选参数
        Map<String, Object> params = new HashMap<>();
        if (childName != null && !childName.isEmpty()) {
            params.put("childName", childName);
        }
        if (phone != null && !phone.isEmpty()) {
            params.put("phone", phone);
        }
        if (communityId != null) {
            params.put("communityId", communityId);
        }
        return childMapper.findAll(params);
    }

    @Override
    public Child findChild(String phone) {
        return childMapper.findChild(phone);
    }

    @Override
    public Child findChildById(int id) {
        return childMapper.findChildById(id);
    }

    @Override
    public void delChild(int id) {
        childMapper.delChild(id);
    }

    @Override
    public void updateChild(Child child) {
        childMapper.updateChild(child);
    }

    @Override
    public List<Child> getCommunityChild(int communityId) {
        return childMapper.getCommunityChild(communityId);
    }
}
